package com.portal.settings;

import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;

import java.util.Optional;

/**
 * 设置 本地存储
 *
 * @author Amadeus
 * @date 2025/02/26
 */
public class SettingsLocalStorage {

    private static final Table<Long, String, Table<String, String, Object>> SETTINGS_CONTAINER = HashBasedTable.create();

    public static void put(Long tenantId, String virtualRegion, String group, String name, Object value) {
        SETTINGS_CONTAINER.row(tenantId)
                .computeIfAbsent(virtualRegion, k -> HashBasedTable.create())
                .put(group, name, value);
    }

    public static Object get(Long tenantId, String virtualRegion, String group, String name) {
        return Optional.ofNullable(SETTINGS_CONTAINER.get(tenantId, virtualRegion))
                .map(table -> table.get(group, name))
                .orElse(null);
    }

}

